<?php
	include_once ("auth.php");
	include_once ("sgbd.php");

	function isAdmin () {
		return ($_COOKIE['login'] == 'bourtaillar');
	}
	
	function sendConfirm ($login, $passwd, $email) {
		$msg = "Vous avez été correctement enregistré(e) sur le site avec l'identifiant $login.\n\n";
		
		mail ($email, "Confirmation", $msg);
	}

	if (md5($_GET['login']) != $_GET['key']) {
		print ("<html><h3> Action invalide !</h3></html>");
		exit (1);
	}
	
	if ($_GET['action'] == 'adduser') {
		$login = $_GET['login'];
		$passwd = $_GET['passwd'];
		$lastname = $_GET['lastname'];
		$firstname = $_GET['firstname'];
		$email = $_GET['email'];
		
		$res = query ("INSERT INTO USER VALUES ('$login', '$lastname', '$firstname', '$email', '$passwd')");
		
		if ($res) {
			print ("<html><h3> Ajout r&eacute;ussi !</h3></html>");
			
			sendConfirm ($login, $passwd, $email);
		}
	}
?>
